#ifndef __PARSER_H
#define __PARSER_H

#include <string>
#include "number.h"

using namespace std;

/** Generic parser interface.
 */
class Parser {

  protected:
    /** A string to identify the parser.
     * Uniqueness is not required but very useful.
     * However, each parser sets its own name, there is no way to change it
     * from the outside.
     */
    string name;

  public: 
    /** A 'do not touch' field. 
     * Refers to Number::NOTANUMBER
     */
    static Number *NOTANUMBER;
    /** A 'do not touch' field.
     * Refers to the null (\0) char.
     */
    static char    NOTANOPERATOR;
    /** A string of characters that are safe to be ignored during parsing.
     * Ideally, it should include dash (-) but it is an operator and a sign,
     * so it's not safe to include it. Therefore, it is really for whitespace,
     * but can be adjusted if you are brave enough.
     */
    static const string WHITESPACE;

    /** Default c'tor. */
    Parser();

    /** Parses input for a number.
     * Updates position within input and returns a number.
     *
     * @param input the input to be parsed
     * @param pos   the starting position for parsing. It is updated to the 
     *		    position where parsing ends.
     *
     * @return the parsed value. If the number cannot be parsed, returns 
     *         NOTANUMBER
     */
    virtual Number *parseNum(string input, size_t &pos) const = 0;

    /** Parses input for an operator .
     * Updates position within input and returns an operator (char).
     *
     * @param input the input to be parsed
     * @param pos   the starting position for parsing. It is updated to the 
     *		    position where parsing ends.
     *
     * @return the parsed operator. 
     *	       If the operator cannot be parsed, returns NOTANOPERATOR
     * 
     */
    virtual char parseOp(string input, size_t &pos) const = 0;

    /** Returns a unique name of the parser.
     */
    const string getName();
};

#endif
